package com.zx._06_JVM.chapter_02_gc;

import java.util.ArrayList;
import java.util.List;

/**
 * Function:堆内存溢出
 *
 * @author crossoverJie
 *         Date: 29/12/2017 18:22
 * @since JDK 1.8
 */
public class HeapOOM {

    public static void main(String[] args) {
        // 1. 发生内存逃逸演示
        new HeapOOM().demo1();

        // 2. 不发生内存逃逸
        //HeapOOM.demo2();
    }

    public static void demo2() {
        List<String> list = new ArrayList<>(10);
        while (true) {
            list.add("1");
        }
    }

    public void demo1() {
        List<String> list = new ArrayList<>(10);
        while (true) {
            list.add("1");
        }
    }
}
